import { useEffect, useState } from 'react';

const useSelectCondition = conditionList => {
    const [selectList, setSelectList] = useState([]);

    useEffect(() => {
        const newSelectList = conditionList?.length > 0
            ? conditionList.map(condition => {
                const { code: value, value: name, ...otherProps } = condition;

                return {
                    value,
                    name,
                    ...otherProps
                };
            })
            : [];

        setSelectList(newSelectList);
    }, [conditionList]);

    return selectList;
};

export default useSelectCondition;
